<?

//require_once(dirname(__FILE__) . '/array.php');

class bf_request extends bf_array {

	protected $opts;
	
	public function __construct($options = array()) {
		$this->opts = array_merge(array(
			'params' => array_merge($_POST, $_GET),
			'files' => $_FILES,
		), $options);
		$this->data = $this->from_array($this->opts['params'])->to_array();
	}
	
	public function file($name, $default = false) {
		if (	!isset($this->opts['files'][$name]) ||
			!isset($this->opts['files'][$name]['name']) ||
			!isset($this->opts['files'][$name]['tmp_name']) ||
			!isset($this->opts['files'][$name]['error']) ||
			!isset($this->opts['files'][$name]['size']) ||
			!isset($this->opts['files'][$name]['type']) ||
			$this->opts['files'][$name]['error'] != 0 ||
			$this->opts['files'][$name]['size'] == 0
		) return $default;
		return (object) $this->opts['files'][$name];
	}

	public function is_ajax() {
		return $_SERVER['HTTP_X_REQUESTED_WITH'] === 'xmlhttprequest';
	}
}

?>